﻿using System;
using System.Collections.Generic;
using Channelvn.Cached.UrlRewrite;
using Core.Library;
using DataObject.News;

namespace Event
{
    public partial class NewsDetails : System.Web.UI.Page
    {
        #region variables, constants, properties
        private long _id;
        private const int _pageSizeNewsUpdate = 5;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            _id = Utils.GetLongIdFromRequestString(Utils.Id, 0);

            if (!IsPostBack && _id > 0)
            {
                #region news details
                {
                    var dt = NewsCache.News_GetDetails(
                        id: _id);

                    if (dt == null || dt.Rows.Count == 0) _301Redirection._404Redirect();

                    this.ctrDetails.Visible = this.ctrDetails.DataBind(dt);
                }
                #endregion

                #region list other news
                {
                    var exceptionId = new List<long>();
                    exceptionId.Add(_id);
                    var dt = NewsCache.News_GetOtherNews(1, _pageSizeNewsUpdate, exceptionId);
                    this.ctrBoxNewsUpdate.Visible = this.ctrBoxNewsUpdate.DataBind(dt);
                }
                #endregion

                return;
            }

            _301Redirection._404Redirect();
        }
    }
}